<?php
/**
 * Created by PhpStorm.
 * Power By Mikkle
 * Email：776329498@qq.com
 * Date: 2017/9/11
 * Time: 16:13
 */

namespace mikkle\tp_wechat\src;


use mikkle\tp_wechat\base\WechatBase;
use mikkle\tp_wechat\support\Curl;
use mikkle\tp_master\Log;
use mikkle\tp_wechat\support\StaticFunction;

class Sapp extends WechatBase
{

    const JS_CODE2_SESSION = '/sns/jscode2session?';

    public function  __construct($options=[])
    {
        parent::__construct($options);
    }

    /**
     * 用小程序的code获取用户的session_key
     * @param $code
     *
     * @return bool|mixed
     */
    public function login($code){
        $this->getToken();
        if (!$this->access_token || empty($openid)){
            return false;
        }
        $curl_url = self::API_BASE_URL_PREFIX .  self::JS_CODE2_SESSION . "appid={$this->appId}&secret={$this->secret}&js_code=$code&grant_type=authorization_code";
        $result = Curl::curlGet($curl_url) ;
        return $this->resultJsonWithRetry($result,__FUNCTION__, func_get_args());

    }


}